package com.qf.controller;

import com.qf.pojo.Patient;
import com.qf.pojo.Registration;
import com.qf.service.RegistrationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;


@RestController
@RequestMapping("/registration")
public class RegistrationController {
    @Autowired
    private RegistrationService registrationService;

    @RequestMapping("/insert")
    public String insert(@RequestBody Registration registration, HttpSession session){
        int insert = registrationService.insert(registration);
        if(insert==1){
            session.setAttribute("registId",registration.getRegistId());
            return "success";
        }else {
            return "error";
        }
    }
    @RequestMapping("/selectById")
    public Registration selectById(@RequestBody Map map){
        String registId=(String)map.get("registId");
        Registration registration=new Registration();
        registration.setRegistId(registId);
        List<Registration> registrations = registrationService.selectAll(registration);
        if(!registrations.isEmpty()){
            return registrations.get(0);
        }
        else return null;
    }
    @RequestMapping("/selectByState")
    public List<Registration> selectByState(@RequestBody Map map){
        String state = (String)map.get("state");
        Registration registration=new Registration();
       registration.setStates(state);
        List<Registration> registrations = registrationService.selectAll(registration);
        if(!registrations.isEmpty()){
            return registrations;
        }
        else return null;
    }


}
